# ==============================================================================
# Copyright (c) 2025 CompanyName. All rights reserved.
# Author:         22020873 陈泽欣
# Project:        Design of Deep Learning Fundamental Course
# Module:         norm_data.py
# Date:           2025-05-24
# Description:    本模块用于定义系统中使用的标准化数据与配置参数，包括颜色阈值、相机内参、骰子三维点集等。
#                 主要功能包括：
#                 - 定义 HSV 色彩空间下的多种颜色掩膜范围（红、蓝、绿、黄、橙、黑）；
#                 - 提供骰子的 3D 关键点坐标（8个角点），用于 PnP 和姿态估计；
#                 - 存储相机标定参数（内参矩阵 camera_matrix 和畸变系数 dist_coefs）；
#                 - 映射骰子面索引到颜色名称与标签语义（colors_dict, labels_dict）；
#                 - 提供画图用的颜色列表及随机配色方案；
#                 是整个骰子姿态识别系统中共享常量与配置数据的核心数据模块。
# ==============================================================================

import random
import numpy as np

lower_red1 = np.array([0, 100, 100])
upper_red1 = np.array([10, 255, 255])
lower_red2 = np.array([160, 100, 100])
upper_red2 = np.array([180, 255, 255])

lower_blue = np.array([100, 150, 0])
upper_blue = np.array([140, 255, 255])

lower_green = np.array([40, 50, 50])
upper_green = np.array([90, 255, 255])

lower_yellow = np.array([15, 125, 125])
upper_yellow = np.array([30, 255, 255])

lower_orange = np.array([10, 100, 100])
upper_orange = np.array([25, 255, 255])

lower_cyan = np.array([80, 150, 150])
upper_cyan = np.array([100, 255, 255])

lower_black = np.array([0, 0, 0])
upper_black = np.array([180, 255, 30])


dice_3d_points = np.float32([
    [-5.12, -5.12, 10.24],  # top layer
    [5.12, -5.12, 10.24],
    [5.12, 5.12, 10.24],
    [-5.12, 5.12, 10.24],

    [-5.12, -5.12, 0],      # bottom layer
    [5.12, -5.12, 0],
    [5.12, 5.12, 0],
    [-5.12, 5.12, 0]
])

camera_matrix = np.array(([959.45925354,  0,        958.79245016],
                          [0.00000000e+00, 959.64046054, 539.77893023],
                          [0.00000000e+00, 0.00000000e+00, 1.00000000e+00]), dtype=np.double)

dist_coefs = np.array([1.92493068e-03, -2.07295872e-02, 7.32289887e-05, -3.37568608e-04, 4.28981155e-02], dtype=np.double)

fx = camera_matrix[0, 0]
fy = camera_matrix[1, 1]
cx = camera_matrix[0, 2]
cy = camera_matrix[1, 2]

colors_dict = {
    0: 'orange',
    1 : 'red',
    2 : 'green',
    3 : 'yellow',
    4 : 'cyan',
    5 : 'blue',
}

labels_dict = {
    0: 'one',
    1 : 'two',
    2 : 'three',
    3 : 'four',
    4 : 'five',
    5 : 'six',
}

# labels_dict = {
#     0: 'orange_one',
#     1 : 'red_two',
#     2 : 'green_three',
#     3 : 'yellow_four',
#     4 : 'cyan_five',
#     5 : 'blue_six',
# }

# 定义颜色列表，BGR格式
colors_list = [
    (0, 255, 0), (0, 0, 255), (255, 0, 0), (255, 255, 0), (56, 56, 255), (151, 157, 255),
    (31, 112, 255), (29, 178, 255), (49, 210, 207), (10, 249, 72), (0, 0, 0), (193, 182, 255),
    (203, 192, 255), (60, 20, 220), (245, 240, 255), (147, 112, 219), (180, 105, 255), (147, 20, 255),
    (133, 21, 199), (214, 112, 218), (216, 191, 216), (221, 160, 221), (238, 130, 238), (255, 0, 255),
    (255, 0, 255), (139, 0, 139), (128, 0, 128), (211, 85, 186), (211, 0, 148), (204, 50, 153),
    (130, 0, 75), (226, 43, 138), (219, 112, 147), (238, 104, 123), (205, 90, 106), (255, 24, 30),
    (255, 248, 240), (255, 0, 0), (205, 0, 0),  (112, 25, 25), (128, 0, 0), (225, 105, 65),
    (237, 149, 100), (222, 196, 176), (153, 204, 224), (153, 136, 119), (144, 128, 112), (255, 144, 30),
]
draw_color_list = [random.choice(colors_list) for _ in range(20)]


# Start 按钮
btn_start_styleSheet = ("""
    QPushButton {
        background-color: #00BFFF;  /* 青蓝色 */
        color: white;
        border-radius: 8px;
        padding: 6px 12px;
        font-weight: bold;
    }
    QPushButton:hover {
        background-color: #009ACD;  /* 悬停时更深一点的蓝色 */
    }
""")

# Stop 按钮
btn_stop_styleSheet = ("""
    QPushButton {
        background-color: #FF4C4C;  /* 红色 */
        color: white;
        border-radius: 8px;
        padding: 6px 12px;
        font-weight: bold;
    }
    QPushButton:hover {
        background-color: #FF1C1C;  /* 悬停时更深一点的红色 */
    }
""")


line_edit_styleSheet = ("""
QLabel {
    font-size: 12px;
    font-weight: 500;
}

/* QLineEdit 输入框基础样式 */
QLineEdit {
    width: 35px;
    height: 12px;
    background-color: #05060f0a;
    border-radius: 6px;
    font-size: 12px;
    text-align: center;
    font-weight: lighter;
    border: 2px solid transparent;
}

/* 悬停或聚焦时的输入框样式 */
QLineEdit:hover,
QLineEdit:focus {
    border-color: #05060f;
}
""")